import qs from 'qs';
import { myHome } from '../api';

export default {
  namespace: 'vehicle',
  state: {
    userMsg: {
      id: null,
      loginAccount: null,
      location: null
    },
    data: []
  },
  effects: {
    * update({ payload: {  params, func } }, { call, put }) {
      const { jsonResult } = yield call(myHome.devicesAction, params);
      if (typeof func === 'function') {
        func(jsonResult);
      }
    },
    * receive({ payload: {  params, func } }, { call, put }) {
      const { jsonResult } = yield call(myHome.receive, params);
      if (typeof func === 'function') {
        func();
      }
    },
    * list({ payload: params }, { call, put }) {
      const { jsonResult } = yield call(myHome.deviceList, params);
      yield put({
        type: 'queryListSuccess',
        payload: {
          data: jsonResult.data
        }
      });
    }
  },
  reducers: {
    queryListSuccess(state, {
      payload
    }) {
      return {
        ...state,
        ...payload
      };
    }
  }
};
